#include <iostream>
#include <algorithm>
#include <string>
#include <list>
using namespace std;

int n;
typedef struct
{
    string name;
    string number;
    int ChengJi;
    //int ID;
} Student;
//list<Student> LianBiao;
Student Max;
Student Min;
Student DangQian;
int main()
{
    cin >> n;
    cin >> DangQian.name >> DangQian.number >> DangQian.ChengJi;
    Max = Min = DangQian;
    n--;
    while (n--)
    {
        DangQian.name.clear();
        DangQian.number.clear();
        cin >> DangQian.name >> DangQian.number >> DangQian.ChengJi;
        if (DangQian.ChengJi > Max.ChengJi)
        {
            Max = DangQian;
        }
        if (DangQian.ChengJi < Min.ChengJi)
        {
            Min = DangQian;
        }
    }
    cout << Max.name << " " << Max.number << endl;
    cout << Min.name << " " << Min.number << endl;
    return 0;
}